home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CTOOLS10.ARJ / DEBUG.H < prev    next >
C/C++ Source or Header  |  1992-03-20  |  6KB  |  181 lines

  1. /****************************************************************************
  2. *
  3. *                    Copyright (C) 1991 Kendall Bennett.
  4. *                            All rights reserved.
  5. *
  6. * Filename:        $RCSfile: debug.h $
  7. * Version:        $Revision: 1.6 $
  8. *
  9. * Language:        ANSI C
  10. * Environment:    any
  11. *
  12. * Description:    General header file for portable code.
  13. *
  14. * $Id: debug.h 1.6 92/03/15 12:51:48 kjb Exp $
  15. *
  16. * Revision History:
  17. * -----------------
  18. *
  19. * $Log:    debug.h $
  20. * Revision 1.6  92/03/15  12:51:48  kjb
  21. * Added MK_FP macro and ushort typedef.
  22. * Revision 1.5  91/10/28  03:17:33  kjb
  23. * Ported to the Iris.
  24. * Revision 1.4  91/09/26  15:29:02  kjb
  25. * Added stuff for the SGI Iris 4D.
  26. * Revision 1.3  91/09/26  10:07:04  kjb
  27. * Added general typedef stuff.
  28. * Revision 1.2  91/09/03  18:19:14  ROOT_DOS
  29. * Added a few defines that are supplied by <dir.h> for UNIX compatibility.
  30. *
  31. * Revision 1.1  91/08/16  13:19:06  ROOT_DOS
  32. * Initial revision
  33. *
  34. ****************************************************************************/
  35.  
  36. #ifndef    __DEBUG_H
  37. #define    __DEBUG_H
  38.  
  39. #ifdef    DEBUG
  40. #        define D(x) x
  41. #else
  42. #        define D(x)
  43. #endif
  44.  
  45. #define    PRIVATE    static
  46. #define    PUBLIC
  47.  
  48. #ifdef     __MSDOS__                /* Compiling for MSDOS                    */
  49. #        define MS(x) x
  50. #        define UX(x)
  51. #        define IR(x)
  52. #        define _8086        /* We know we have an 8086 type processor    */
  53. #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
  54. #        define LDATA
  55. #        define NULL    0L
  56. #else
  57. #        define NULL    0
  58. #endif
  59. #else    __MSDOS__
  60. #ifdef    __IRIS4D__                /* Compiling for the SGI Iris 4D        */
  61. #        define MS(x)
  62. #        define UX(x) x            /* The Iris is a UNIX machine            */
  63. #        define IR(x) x
  64. #        define O_BINARY 0        /* no binary input mode in UNIX open()    */
  65. #        define MAXFILE    255        /* These are defined in <dir.h>, but    */
  66. #        define MAXDIR    255        /* on UNIX machines, we just define        */
  67. #        define MAXPATH    255        /* them all to be the same size            */
  68. #        define far                /* Near and far do not exist under        */
  69. #        define near                /* UNIX or the Iris.                    */
  70. #        define NULL ((void *)0)
  71. #else    __IRIS4D__                /* Assume UNIX compilation                */
  72. #        define MS(x)
  73. #        define UX(x) x
  74. #        define IR(x)
  75. #        define O_BINARY 0        /* no binary input mode in UNIX open()    */
  76. #        define MAXFILE    255        /* These are defined in <dir.h>, but    */
  77. #        define MAXDIR    255        /* on UNIX machines, we just define        */
  78. #        define MAXPATH    255        /* them all to be the same size            */
  79. #        define far                /* Near and far do not exist under        */
  80. #        define near                /* UNIX or the Iris.                    */
  81. #        define NULL ((void *)0)
  82. #endif    __IRIS4D__
  83. #endif    __MSDOS__
  84.  
  85. /****************************************************************************
  86. *
  87. *    SEG(p)        Evaluates to the segment portion of an 8086 address.
  88. *    OFF(p)        Evaluates to the offset portion of an 8086 address.
  89. *    FP(s,o)        Creates a far pointer given a segment offset pair.
  90. *    PHYS(p)        Evaluates to a long holding a physical address
  91. *
  92. ****************************************************************************/
  93.  
  94. #ifdef    _8086
  95. #        define SEG(p)    ( ((unsigned *)&(void far *)(p))[1] )
  96. #        define OFF(p)    ( (unsigned)(p) )
  97. #        define FP(s,o)    ( (void far *)( ((unsigned long)s << 16) +    \
  98.                           (unsigned long)o ))
  99. #        define PHYS(p)    ( (unsigned long)OFF(p) +                        \
  100.                           ((unsigned long)SEG(p) << 4))
  101. #else
  102. #        define PHYS(p)     (p)
  103. #endif    _8086
  104.  
  105. /****************************************************************************
  106. *
  107. *    NUMELE(array)        Evaluates to the array size in elements
  108. *    LASTELE(array)        Evaluates to a pointer to the last element
  109. *    INBOUNDS(array,p)    Evaluates to true if p points into the array
  110. *    RANGE(a,b,c)        Evaluates to true if a <= b <= c
  111. *    max(a,b)            Evaluates to a or b, whichever is larger
  112. *    min(a,b)            Evaluates to a or b, whichever is smaller
  113. *    ABS(a)                Evaluates to the absolute value of a
  114. *    NBITS(type)            Returns the number of bits in a variable of the
  115. *                        indicated type
  116. *    MAXINT                Evaluates to the value of the largest signed integer
  117. *
  118. ****************************************************************************/
  119.  
  120. #define    NUMELE(a)        (sizeof(a)/sizeof(*(a)))
  121. #define    LASTELE(a)        ((a) + (NUMELE(a)-1))
  122. #ifdef    LDATA
  123. #define    TOOHIGH(a,p)    ((long)PHYS(p) - (long)PHYS(a) > (long)(NUMELE(a)-1))
  124. #define    TOOLOW(a,p)        ((long)PHYS(p) - (long)PHYS(a) < 0)
  125. #else
  126. #define    TOOHIGH(a,p)    ((long)(p) - (long)(a) > (long)(NUMELE(a)-1))
  127. #define    TOOLOW(a,p)        ((long)(p) - (long)(a) < 0)
  128. #endif
  129. #define    INBOUNDS(a,p)    ( ! (TOOHIGH(a,p) || TOOLOW(a,p)) )
  130.  
  131. #define    _IS(t,x) (((t)1 << (x)) != 0)    /* Evaluates true if the width of */
  132.                                         /* variable of type t is < x.      */
  133.                                         /* The != 0 assures that the      */
  134.                                         /* answer is 1 or 0                  */
  135.  
  136. #define    NBITS(t) (4 * (1 + _IS(t,4) + _IS(t,8) + _IS(t,12) + _IS(t,16) \
  137.                          + _IS(t,20) + _IS(t,24) + _IS(t,28) + _IS(t,32)))
  138.  
  139. #define    MAXINT            (((unsigned)~0) >> 1)
  140.  
  141. #ifndef    MAX
  142. #        define MAX(a,b)    ( ((a) > (b)) ? (a) : (b))
  143. #endif
  144. #ifndef    MIN
  145. #        define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
  146. #endif
  147. #ifndef    ABS
  148. #        define ABS(a)    ((a) >= 0 ? (a) : -(a))
  149. #endif
  150.  
  151. #define    RANGE(a,b,c)    ( (a) <= (b) && (b) <= (c) )
  152.  
  153. /* General typedefs    */
  154.  
  155. #ifndef    __GENDEFS
  156. #define    __GENDEFS
  157. typedef    void            *ptr;
  158. typedef void near        *nearptr;
  159. typedef    void far        *farptr;
  160. typedef    unsigned char    uchar;
  161. typedef    unsigned short    ushort;
  162. typedef    unsigned int    uint;
  163. typedef    unsigned long    ulong;
  164. typedef    int                bool;
  165. #endif    __GENDEFS
  166.  
  167. /* Boolean truth values */
  168.  
  169. #define    false        0
  170. #define    true        1
  171. #define    FALSE        0
  172. #define    TRUE        1
  173. #define    NO            0
  174. #define    YES            1
  175.  
  176. #endif    __DEBUG_H
  177.